<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>天天健康</title>
        <meta name="description" content="天天健康">
        <meta name="keywords" content="天天健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>检查组管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="手机号/姓名" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row ref="multipleTable" @selection-change="handleSelectionChange">
                        <el-table-column type="selection" width="55" label="选择" align="center" :selectable="selectable"></el-table-column>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center" :formatter="dateFormat"></el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="uname" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                        <el-table-column prop="sname" label="套餐名称" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                        <el-table-column style="width: 400px;" label="操作" align="center" >
                            <template slot-scope="scope">
                                <!--<el-button type="primary" size="mini" @click="orderConsent(scope.row)" :style="{ display: visibleCancel }">确认</el-button>-->
                                <el-button size="mini" type="danger" @click="orderCancel(scope.row)" :style="{ display: visiblePublish }">取消预约</el-button>
                                <el-button size="mini" type="danger" @click="orderDelete(scope.row)" :style="{ display: visibleDelete }">删除</el-button>
                                <el-button type="primary" size="mini"  @click="theHappy()" :style="{ display: visibleSubmit }">详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div slot="footer" class="dialog-footer">
                        <el-button type="danger" class="butT" @click="allDelete()" >删除选中</el-button>
                    </div>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="uname">
                                                        <el-input v-model="formData.uname"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号码" prop="phoneNumber">
                                                        <el-input v-model="formData.phoneNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证号" prop="idCard">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="体检日期" prop="orderDate">
                                                        <el-input v-model="formData.orderDate" type="date"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别" prop="sex">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="档案号" prop="fileNumber">
                                                        <el-input v-model="formData.fileNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="备注">
                                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
									<div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>选择</th>
                                                <th>套餐编码</th>
                                                <th>套餐名称</th>
                                                <th>套餐说明</th>
                                                <th>套餐价格</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="c in tableData">
                                                <td>
                                                    <input :id="c.id" v-model="checkitemIds" type="checkbox"  :value="c.id">
                                                </td>
                                                <td><label :for="c.id">{{c.code}}</label></td>
                                                <td><label :for="c.id">{{c.name}}</label></td>
                                                <td><label :for="c.id">{{c.remark}}</label></td>
                                                <td><label :for="c.id">{{c.price}}</label></td>
                                            </tr>
                                            </tbody>
                                        </table>
									</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:8,
                    queryString:null,
                },
                return: {
                    multipleSelectionFlag:false,
                    multiDeleteVisible:true,
                    multipleSelection:''
                 },
                dataList: [],//列表数据
                formData: {},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                msg:"",//记录每一条的信息，便于取id
                delarr:[],//存放删除的数据
                multipleSelection: [],//存放选中值的数组
                setmealId:null,
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
                visiblePublish: '',//绑定取消预约按钮
                visibleSubmit: '',//绑定查看详情按钮
                visibleDelete :'',//绑定删除按钮
                rules: {//校验规则
                    uname: [{ required: true, message: '姓名为必填项', trigger: 'blur' }],
                    phoneNumber: [{ required: true, message: '手机号码为必填项', trigger: 'blur' }],
                    idCard: [{ required: true, message: '身份证号为必填项', trigger: 'blur' }],
                    sex: [{ required: true, message: '性别为必填项', trigger: 'blur' }],
                    fileNumber: [{ required: true, message: '档案号为必填项', trigger: 'blur' }],
                    remark: [{ required: true, message: '备注为必填项', trigger: 'blur' }],
                    orderDate: [{ required: true, message: '体检日期为必填项', trigger: 'blur' }]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //添加
                handleAdd () {
                    //发送ajax请求，需要提交检查组基本信息和勾选的检查项信息
                    //console.log(this.formData);
                    //alert(this.checkitemIds);
                    axios.post("/ordermanage/add.do?checkitemIds=" + this.checkitemIds,this.formData).then((res) => {
                        if(res.data.flag){
                            //执行成功，关闭新增窗口
                            this.dialogFormVisible = false;
                            //弹出提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //分页查询
                            this.findPage();
                        }else{
                            //执行失败，弹出提示信息
                            this.$message.error(res.data.message);
                        }
                    });
                },
                //分页查询
                findPage() {
                    //封装分页查询条件
                    var param = {
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    };
                    //发送ajax请求，进程分页查询
                    axios.post("/ordermanage/findPage.do",param).then((res) => {
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total;
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                    this.activeName = 'first';
                    this.checkitemIds = [];
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    this.dialogFormVisible = true;//弹出窗口
                    //发送ajax请求，查询所有的套餐信息，以表格的形式展示到窗口中
                    axios.get("/ordermanage/allSetmeals.do").then((res) => {
                        if(res.data.flag){
                            //查询成功，为tableData赋值
                            this.tableData = res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 取消预约
                orderCancel(row) {//row其实是一个json对象，json对象的结构为{"age":"0-100","attention":"无","code":"0011","id":38,"name":"白细胞计数","price":10.0,"remark":"白细胞计数","sex":"0","type":"2"}
                    //alert(row.id);
                    this.$confirm("你确定要取消当前预约吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定按钮，发送ajax请求，将预约信息的ID提交到Controller进行处理
                        axios.post("/ordermanage/cancel.do", row).then((res) => {
                            if(res.data.flag){
                                //执行成功
                                //弹出成功提示信息
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                //重新进行分页查询
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r)=>{
                            this.showMessage(r);
                        });
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                },
                // 删除未到诊和取消预约的预约信息
                orderDelete(row) {//row其实是一个json对象，json对象的结构为{"age":"0-100","attention":"无","code":"0011","id":38,"name":"白细胞计数","price":10.0,"remark":"白细胞计数","sex":"0","type":"2"}
                    //alert(row.id);
                    this.$confirm("你确定要删除当前预约吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                        axios.post("/ordermanage/delete.do",row).then((res) => {
                            if(res.data.flag){
                                //执行成功
                                //弹出成功提示信息
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                //重新进行分页查询
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r)=>{
                            this.showMessage(r);
                        });
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                },
                // 批量删除未到诊的预约信息
                allDelete(){
                    this.$confirm("你确定要删除选中的所以预约吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将预约信息的ID提交到Controller进行处理
                    const length = this.multipleSelection.length;
                    for (let i = 0; i < length; i++) {
                        //alert(this.multipleSelection[i].id);
                        axios.get("/ordermanage/delete.do?id=" + this.multipleSelection[i].id).then((res) => {
                            if(res.data.flag){
                                //执行成功
                                //弹出成功提示信息
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                //重新进行分页查询
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r)=>{
                            this.showMessage(r);
                        });
                        //this.delarr.push(this.multipleSelection[i].id);
                    }
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                },
                //按钮显示控制
                selectable(row){
                    if(row.orderStatus === "已到诊"){
                        this.visiblePublish = 'none';
                        this.visibleSubmit = '';
                        this.visibleDelete = 'none';
                        return true;
                    }else if(row.orderStatus === "取消预约"){
                        this.visiblePublish = 'none';
                        this.visibleSubmit = '';
                        this.visibleDelete = '';
                        return true;
                    }else if(row.orderStatus === "预约中"){
                        this.visiblePublish = '';
                        this.visibleSubmit = 'none';
                        this.visibleDelete = 'none';
                        return true;
                    }else {
                        this.visiblePublish = 'none';
                        this.visibleSubmit = 'none';
                        this.visibleDelete = '';
                        return true;
                    }

                },
                handleSelectionChange(val) {
                    this.multipleSelection = val;
                },
                theHappy(){
                    alert("尊敬的用户,目前此功能只对付费版高级管理员开放，为您带来不便敬请谅解！");
                },
                //时间格式化
                dateFormat:function(row,column){
                    var t=new Date(row.orderDate);//row 表示一行数据, updateTime 表示要格式化的字段名称
                    return t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate();
                },
                //权限不足提示
                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                }

            }
        })
    </script>
</html>
